<%--
  Created by IntelliJ IDEA.
  User: WangWeiwei
  Date: 16-10-19
  Time: 上午11:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path;
    request.setAttribute("basePath", basePath);
%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<div>
    <div class="title">

        <h3>
            <%--商品类别与标题--%>
            <span class="label label-success">${goods.type.name}</span>
            &nbsp; ${goods.goodsName}
        </h3>
    </div>
    <div>
        <%--商品操作---只有管理员才会显示此按钮--%>
        <div class="span3">
            <select id="goods-operate-in-goods-detail" class="form-control select select-primary select-block mbl">
                    <option value="0">操作</option>
                    <option value="1">关闭</option>
                    <option value="1">修改</option>
                    <option value="3">删除</option>
            </select>
        </div>
        <script>
            $(function () {
                $("#goods-operate-in-goods-detail").select2({dropdownCssClass: 'dropdown-inverse'});
                $("#goods-operate-in-goods-detail").change(function(){
                    console.log($(this).val());
                    if($(this).val() == 1){
                        $(window.parent.document).find('#tab_tab_goods-detail-<c:out value='${goods.id}'>1</c:out>').remove();
                        $(window.parent.document).find('#tab_goods-detail-<c:out value='${goods.id}'>1</c:out>').remove();
                        $(window.parent.document).find("a[aria-controls='home']").click();
                    }
                })
            })
        </script>
    </div>
    <div class="content">
        <div class="palette-paragraph">
            <ul>
                <li>规格: <cite title="Source Title">${goods.standard}</cite></li>
                <li>条码: <cite title="Source Title">${goods.code}</cite></li>
            </ul>
        </div>
        <div class="tabbable" id="tabs-973031"><!-- Only required for left/right tabs -->

            <div class="panel panel-default">
                <!-- Default panel contents -->
                <div class="panel-heading">
                    <ul class="nav nav-tabs">
                        <li class="active">
                            <a data-toggle="tab" href="#panel-detail-goods-${goods.id}2">适用症状</a>
                        </li>
                        <li>
                            <a data-toggle="tab" href="#panel-detail-goods-${goods.id}3">适用作物</a>
                        </li>
                        <li>
                            <a data-toggle="tab" href="#panel-detail-goods-${goods.id}1">生产厂商</a>
                        </li>
                    </ul>
                </div>
                <div class="panel-body">
                    <div class="tab-content">
                        <%--产品用途--%>
                        <div class="tab-pane active" id="panel-detail-goods-${goods.id}2">
                            <c:forEach items="${goods.sympton}" var="sym">
                                <label class="checkbox success" for="checkbox2c">
                                    <input type="checkbox" data-toggle="radio"
                                           checked="checked" value="" id="checkbox2c"
                                           class="custom-checkbox">
                                    <span class="icons">
                                        <span class="icon-checked"></span>
                                    </span>
                                        ${sym.name}
                                </label>
                            </c:forEach>
                        </div>
                        <%--适用作物--%>
                        <div class="tab-pane" id="panel-detail-goods-${goods.id}3">
                            <c:forEach items="${goods.crop}" var="crops">
                                <label class="checkbox success" for="checkbox2c">
                                    <input type="checkbox" data-toggle="radio"
                                           checked="checked" value="" id="checkbox2c"
                                           class="custom-checkbox">
                                    <span class="icons">
                                        <span class="icon-checked"></span>
                                    </span>
                                        ${crops.name}
                                </label>
                            </c:forEach>
                        </div>
                            <script>
                                $(function () {
                                    function setModalBodyView(data) {
                                        var detailProductorModal = $("#panel-detail-goods-${goods.id}1");
                                        function contratsHTML() {
                                            var html = "";
                                            for(var i in data.contrats){
                                                html += "<footer>" + data.contrats[i].type.name + " : " + data.contrats[i].contrat + "</footer>";
                                            }
                                            html += "</blockquote>";
                                            return html;
                                        }
                                        var HTML =
                                                "<dl class=\"view\">" +
                                                "<blockquote><p>基本信息</p>" +
                                                "<footer>名称 : " + data.name + "</footer>" +
                                                "<footer>企业类型 : " + data.type.type + "</footer>" +
                                                "<footer>营业执照编号 : " + data.code + "</footer></blockquote>" +
                                                "<blockquote><p>联系方式</p>" + contratsHTML() +
                                                "<blockquote><p>详细描述</p>" +
                                                "<div>" + data.describe +"</div></blockquote>" +
                                                "</dl>";

                                        detailProductorModal.html(HTML);
                                        console.log(detailProductorModal);
                                    }

                                    /**为生产厂商按钮添加时间*/
                                    console.log($("a[href='#panel-detail-goods-${goods.id}1']"));
                                    $("a[href='#panel-detail-goods-${goods.id}1']").click(function () {
                                        $.getJSON("${basePath}/manager/goods/productors/detail/goods_id/<c:out value='${goods.id}'>1</c:out>",function (data) {
                                            setModalBodyView(data);
                                        })
                                    });
                                })
                            </script>
                        <div class="tab-pane" id="panel-detail-goods-${goods.id}1">
                            <p><c:out value="${goods.productor.name}">未知</c:out></p>
                            <p><c:out value="${goods.productor.describe}"></c:out></p>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="">
            <div class="panel panel-default">
                <!-- Default panel contents -->
                <div class="panel-heading">
                    ${goods.goodsName} 详情信息
                </div>
            </div>
            <div class="panel-body">
                <c:out value="${goods.describe}">无法检测到商品${goods.goodsName}的描述信息</c:out>
            </div>
        </div>
    </div>

</div>
</div>